<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../react18/react.development.js"></script>
  <script src="../react18/react-dom.development.js"></script>
  <script src="../react18/babel.min.js"></script>
</head>

<body>
  <div id="app"></div>
  <script type="text/babel">
class App extends React.Component{
    state={
        count:0
    }
    render(){
        console.log('render')
        const {count} = this.state
        return (
            <div>
                <button onClick ={this.handle}>累加</button>
                <h1>{count}</h1>
            </div>
        )
    }
    handle =()=>{
        //第一种方法
        // let {count} = this.state
        // this.setState({count:++count})//不能使用count++，因为后++是先返回再自加
        //第二种方法
        this.setState({count:this.state.count+1})//如果不把count解构出来，不能写++this.state.count,因为这样就把原来的state修改了，只能写this.state.count+1

    }

}
const root = ReactDOM.createRoot(document.getElementById('app')).render(<App/>)


  </script>
</body>

</html>